// 顾客端相关的类型定义

// 分类类型
export interface Category {
  id: number;
  name: string;
  icon: string;
  description?: string;
}

// 商家类型
export interface Store {
  id: number;
  name: string;
  description?: string;
  coverImage: string;
  logo?: string;
  rating: number;
  monthSales: number;
  tags: string[];
  status?: string;  // 商店状态: 'OPEN', 'CLOSED', 'BUSY', 'COMING_SOON'
  type?: string;    // 商家类型: '中餐', '快餐', '西餐' 等
  deliveryTime: number;
  deliveryFee: number;
  distance: number;
  minOrder: number;
  promotion?: string;
  address?: string;
  phone?: string;
  businessHours?: string;
  // 后端返回的额外字段
  longitude?: number;
  latitude?: number;
  categoryId?: number;
  monthlySales?: number; // 后端字段名
  averageDeliveryTime?: number; // 后端字段名
  minOrderAmount?: number; // 后端字段名
  hasPromotion?: boolean; // 后端字段名
}

// 食品类型
export interface Food {
  id: number;
  name: string;
  description?: string;
  image: string;
  price: number;
  originalPrice?: number;
  rating: number;
  monthlySales: number;
  storeName?: string;
  storeId?: number;
  categoryId?: number;
  categoryName?: string;
  available?: boolean;
  attributes?: FoodAttribute[];
  reviews?: Review[]; // 添加评价字段
}

// 食品属性类型
export interface FoodAttribute {
  name: string;
  options: FoodAttributeOption[];
  required: boolean;
  multiSelect: boolean;
}

// 食品属性选项类型
export interface FoodAttributeOption {
  name: string;
  price: number;
  default?: boolean;
}

// 购物车项类型
export interface CartItem {
  id: number;
  foodId: number;
  foodName: string;
  foodImage: string;
  price: number;
  quantity: number;
  attributes?: SelectedAttribute[];
  storeId: number;
  storeName: string;
  // 商店相关信息
  storeStatus?: string;    // 商店状态
  deliveryFee?: number;    // 配送费
  minOrder?: number;       // 起送价
  deliveryTime?: number;   // 配送时间
}

// 已选属性类型
export interface SelectedAttribute {
  name: string;
  options: string[];
  additionalPrice: number;
}

// 地址类型
export interface Address {
  id: number;
  name: string;
  phone: string;
  province: string;
  city: string;
  district: string;
  detail: string;
  isDefault: boolean;
  latitude?: number;   // 添加纬度
  longitude?: number;  // 添加经度
}

// 订单类型
export interface Order {
  id: number;
  orderNo: string;
  userId: number;
  storeId: number;
  storeName: string;
  storeImage?: string; // 添加商家头像字段
  totalAmount: number;
  status: string; // 改为字符串类型，匹配实际API响应
  items: OrderItem[];
  address: Address;
  createTime: string;
  payTime?: string;
  deliveryTime?: string;
  completeTime?: string;
  remark?: string;
  deliveryFee: number;
  packageFee: number;
  // 添加缺少的属性
  acceptTime?: string;
  prepareTime?: string;
  pickupTime?: string;
  deliverTime?: string;
  goodsAmount?: number;
  discountAmount?: number;
  paymentAmount?: number;
}

// 订单项类型
export interface OrderItem {
  id: number;
  foodId: number;
  foodName: string;
  foodImage: string;
  price: number;
  quantity: number;
  attributes?: SelectedAttribute[];
  subtotal: number;
  amount?: number; // 添加amount字段以兼容API响应
}

// 订单状态枚举
export enum OrderStatus {
  ORDER_CREATED = 'ORDER_CREATED',           // 用户下单，待支付
  PENDING = 'PENDING',                       // 支付完成，等待商家接单
  MERCHANT_CONFIRMED = 'MERCHANT_CONFIRMED', // 商家已接单
  READY_WAITING_RIDER = 'READY_WAITING_RIDER', // 骑手取餐
  ACCEPTED = 'ACCEPTED',                     // 骑手已接单（兼容旧数据）
  RIDER_ASSIGNED = 'RIDER_ASSIGNED',         // 骑手已接单
  FOOD_PICKED = 'FOOD_PICKED',               // 骑手已取餐
  DELIVERED = 'DELIVERED',                   // 订单已送达
  COMPLETED = 'COMPLETED',                   // 订单已完成
  CANCELLED = 'CANCELLED'                    // 订单已取消
}

// 评价类型
export interface Review {
  id: number;
  orderId: number;
  userId: number;
  userName: string;
  userAvatar?: string;
  storeId: number;
  storeName?: string;
  foodId?: number;
  foodName?: string;
  rating: number;
  content: string;
  images?: string[];
  createTime: string;
  reply?: string;
  replyTime?: string;
}

// 排序字段枚举
export enum StoreSearchSort {
  DISTANCE = 'DISTANCE',
  RATING = 'RATING', 
  PRICE = 'PRICE',
  DELIVERY_TIME = 'DELIVERY_TIME',
  SALES = 'SALES'
}

// 店铺搜索参数类型（符合后端DTO）
export interface StoreQueryDTO {
  keyword?: string;
  categoryId?: number;
  longitude?: number;
  latitude?: number;
  sortBy?: StoreSearchSort;
  minPrice?: number;
  maxPrice?: number;
  page?: number;
  size?: number;
}

// 通用分页参数类型（向后兼容）
export interface PageParams {
  page: number;
  pageSize: number;
  keyword?: string;
  category?: string;
  sortBy?: string;
  sortOrder?: 'asc' | 'desc';
}

// 分页结果类型
export interface PageResult<T> {
  data: T[];
  total: number;
  page: number;
  pageSize: number;
  totalPages: number;
}
